package com.amqp.demo;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class Consumer {
    public static void main(String[] args) throws InterruptedException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfiguration.class);
        //AmqpTemplate amqpTemplate = context.getBean(AmqpTemplate.class);
        RabbitTemplate amqpTemplate = (RabbitTemplate)context.getBean(AmqpTemplate.class);
        // 一般不用这种写法，都是使用监听器模式。
        amqpTemplate.setDefaultReceiveQueue("queue-100");
        while (true){
            Object ss = amqpTemplate.receiveAndConvert();
            if(ss==null){
                Thread.sleep(1000);
                continue;
            }
            System.out.println(ss.getClass());
            System.out.println("Received: " + ss);
        }
    }
}
